package se.energimyndigheten.lampguiden;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

public class InfoFragment extends Fragment{

    public static final String EXTRA_HTML_PATH = "html_path";
    public static final String EXTRA_TITLE = "title";

    private static final String TAG = InfoFragment.class.getSimpleName();

    private WebView mWebView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        setHasOptionsMenu(true);
        return inflater.inflate(R.layout.webview_activity, container, false);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        menu.clear();
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        mWebView = (WebView) getActivity().findViewById(R.id.webview);
        // load web view with provided path
        Bundle args = getArguments();
        String path = args.getString(EXTRA_HTML_PATH);
        loadHtmlFile(path);
    }

    private void loadHtmlFile(String path) {
        path = path != null ? path : "file::///android_asset/404.html";
        //Log.v(TAG, "loadHtmlFile :: path: " + path);
        mWebView.loadUrl(path);
    }

}
